package com.hycc.base;

public class BetterStop implements Runnable{

    //设置一个标识位
    private boolean flag = true;

    @Override
    public void run() {
        int i = 0;
        while(flag){
            System.out.println("run ..." + i++);
        }
    }

    //设置一个公开的方法转换标志位
    public void stop(){
        this.flag =false;
    }

    public static void main(String[] args) {
        BetterStop bs = new BetterStop();

        new Thread(bs).start();

        for (int i = 0; i < 1000; i++) {
            System.out.println("main + "+i);
            if(i==900){
                bs.stop();
                System.out.println("BetterStop 线程停止了");
            }
        }

    }
}
